﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SearchOperationView.aspx.cs"
    Inherits="Demo.Web.Operation.SearchOperationView" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        var commandHandler = function (command, record) {
            switch (command) {
                case "Edit":
                    var win = App.OperationPopup;
                    win.clearContent();
                    win.show();
                    win.setTitle('Modificar Operación');
                    win.load({
                        url: "OperationView.aspx",
                        params: {
                            Id: record.get('OperationId').toString()
                        }
                    });
                    break;
            }
        }
        var onKeyUp = function (field) {
            var v = this.getRawValue(),
                field;

            if (this.startDateField) {
                field = Ext.getCmp(this.startDateField);
                field.setMaxValue();
                this.dateRangeMax = null;
            } else if (this.endDateField) {
                field = Ext.getCmp(this.endDateField);
                field.setMinValue();
                this.dateRangeMin = null;
            }
            field.validate();
        };
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager ID="ResourceManager1" runat="server" />
    <ext:Store ID="stOperations" OnReadData="grdOperationOperation_ReadData" runat="server"
        RemoteSort="true" PageSize="5" AutoLoad="true" RemotePaging="true">
        <Model>
            <ext:Model ID="mdOperations" runat="server">
                <Fields>
                    <ext:ModelField Name="OperationId" Type="Int" />
                    <ext:ModelField Name="Proyect" Type="String" />
                    <ext:ModelField Name="DateStart" Type="String" />
                    <ext:ModelField Name="DateEnd" Type="String" />
                    <ext:ModelField Name="Hour" Type="Int" />
                    <ext:ModelField Name="HourAssigned" Type="Int" />
                </Fields>
            </ext:Model>
        </Model>
        <AutoLoadParams>
            <ext:StoreParameter Name="limit" Value="5" Mode="Value" />
            <ext:StoreParameter Name="start" Value="0" Mode="Value" />
        </AutoLoadParams>
        <Proxy>
            <ext:PageProxy />
        </Proxy>
    </ext:Store>
    <ext:FormPanel ID="FormPanel1" runat="server" AnchorHorizontal="50%" Layout="AnchorLayout"
        Title="Busqueda de Operación" BodyPadding="10" Padding="10">
        <Defaults>
            <ext:Parameter Name="margins" Value="0 5 0 0" Mode="Value" />
        </Defaults>
        <Items>
            <ext:Panel ID="pnFilters" runat="server" Title="Filtros" Layout="AnchorLayout" Collapsible="true"
                AnchorHorizontal="80%" BodyPadding="10" Padding="10" Frame="true">
                <Listeners>
                    <Expand Handler="this.Expand();" />
                    <Collapse Handler="this.Collapse();" />
                </Listeners>
                <Items>
                    <ext:FieldContainer ID="FieldContainer2" runat="server" AnchorHorizontal="100%" Layout="AnchorLayout">
                        <Items>
                            <ext:TextField ID="txtProyecto" AnchorHorizontal="80%" runat="server" FieldLabel="Proyecto" />
                        </Items>
                    </ext:FieldContainer>
                    <ext:FieldContainer ID="FieldContainer1" runat="server" AnchorHorizontal="100%" Layout="AnchorLayout">
                        <Items>
                            <ext:TextField ID="txtResource" AnchorHorizontal="80%" runat="server" FieldLabel="Recurso" />
                        </Items>
                    </ext:FieldContainer>
                    <ext:FieldContainer ID="FieldContainer3" runat="server" Layout="HBoxLayout">
                        <Defaults>
                            <ext:Parameter Name="margins" Value="0 5 0 0" Mode="Value" />
                        </Defaults>
                        <Items>
                            <ext:DateField ID="dtDateStart" Editable="false" Vtype="daterange" EndDateField="dtDateEnd"
                                runat="server" FieldLabel="Fecha Inicio" EnableKeyEvents="true">
                                <Listeners>
                                    <KeyUp Fn="onKeyUp" />
                                </Listeners>
                            </ext:DateField>
                            <ext:DateField ID="dtDateEnd" Editable="false" Vtype="daterange" StartDateField="dtDateStart"
                                runat="server" FieldLabel="Fecha Fin" EnableKeyEvents="true">
                                <Listeners>
                                    <KeyUp Fn="onKeyUp" />
                                </Listeners>
                            </ext:DateField>
                        </Items>
                    </ext:FieldContainer>
                </Items>
                <Buttons>
                    <ext:Button ID="btnSearch" runat="server" Text="buscar" Icon="Find">
                        <DirectEvents>
                            <Click OnEvent="BtnSearch_Click">
                            </Click>
                        </DirectEvents>
                    </ext:Button>
                    <ext:Button ID="btnClean" runat="server" Text="Limpiar" Icon="Cancel">
                        <DirectEvents>
                            <Click OnEvent="BtnClean_Click">
                            </Click>
                        </DirectEvents>
                    </ext:Button>
                </Buttons>
            </ext:Panel>
            <ext:Container runat="server" Layout="AnchorLayout" AnchorHorizontal="80%" BaseCls="x-plain"
                Flex="1">
                <Items>
                    <ext:GridPanel ID="grdOperation" runat="server" StoreID="stOperations" AnchorHorizontal="100%"
                        Layout="AnchorLayout" Title="Operaciones" SortableColumns="false" Draggable="false"
                        EnableColumnHide="false" EnableColumnMove="false" ClicksToEdit="1" AutoScroll="true">
                        <ColumnModel ID="ColumnModel1" runat="server">
                            <Columns>
                                <ext:Column ID="Column1" runat="server" Flex="1" Header="Proyecto" DataIndex="Proyect" />
                                <ext:Column ID="Column2" runat="server" Header="Fecha Inico" DataIndex="DateStart"
                                    Format="dd-MM-yyyy" />
                                <ext:Column ID="Column3" runat="server" Header="Fecha Fin" DataIndex="DateEnd" Format="dd-MM-yyyy" />
                                <ext:Column ID="Column4" runat="server" Header="Horas" DataIndex="Hour" />
                                <ext:Column ID="Column5" runat="server" Header="Horas Asignadas" DataIndex="HourAssigned" />
                                <ext:ImageCommandColumn ID="ImageCommandColumn1" runat="server" Width="20">
                                    <Commands>
                                        <ext:ImageCommand CommandName="Delete" Icon="Delete">
                                            <ToolTip Text="Eliminar" />
                                        </ext:ImageCommand>
                                    </Commands>
                                    <DirectEvents>
                                        <Command OnEvent="BtnDeleteConfirm_Click">
                                            <ExtraParams>
                                                <ext:Parameter Name="id" Value="record.data['OperationId']" Mode="Raw">
                                                </ext:Parameter>
                                            </ExtraParams>
                                        </Command>
                                    </DirectEvents>
                                </ext:ImageCommandColumn>
                                <ext:CommandColumn ID="clmEdit" runat="server" Width="20">
                                    <Commands>
                                        <ext:GridCommand CommandName="Edit" Icon="ApplicationFormEdit">
                                            <ToolTip Text="Editar" />
                                        </ext:GridCommand>
                                    </Commands>
                                    <Listeners>
                                        <Command Handler="commandHandler(command,record);" />
                                    </Listeners>
                                </ext:CommandColumn>
                            </Columns>
                        </ColumnModel>
                        <TopBar>
                            <ext:Toolbar ID="Toolbar1" runat="server">
                            </ext:Toolbar>
                        </TopBar>
                        <SelectionModel>
                            <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" Mode="Multi" />
                        </SelectionModel>
                        <BottomBar>
                            <ext:PagingToolbar ID="PagingToolbar1" runat="server">
                                <Items>
                                    <ext:Label ID="Label1" runat="server" Text="Page size:" />
                                    <ext:ToolbarSpacer ID="ToolbarSpacer1" runat="server" Width="10" />
                                    <ext:ComboBox ID="ComboBox1" runat="server" Width="80">
                                        <Items>
                                            <ext:ListItem Text="5" />
                                            <ext:ListItem Text="10" />
                                            <ext:ListItem Text="20" />
                                            <ext:ListItem Text="25" />
                                            <ext:ListItem Text="50" />
                                        </Items>
                                        <SelectedItems>
                                            <ext:ListItem Value="5" />
                                        </SelectedItems>
                                        <Listeners>
                                            <Select Handler="#{grdOperation}.store.pageSize = parseInt(this.getValue(), 10); #{grdOperation}.store.load();" />
                                        </Listeners>
                                    </ext:ComboBox>
                                </Items>
                            </ext:PagingToolbar>
                        </BottomBar>
                    </ext:GridPanel>
                </Items>
            </ext:Container>
            <ext:Button ID="btnDelete" runat="server" Hidden="true">
                <DirectEvents>
                    <Click OnEvent="BtnDelete_Click" />
                </DirectEvents>
            </ext:Button>
        </Items>
    </ext:FormPanel>
    <ext:Window ID="OperationPopup" runat="server" Icon="ApplicationFormEdit" Width="900"
        Height="500" Hidden="true" Modal="true" Resizable="false" Draggable="false" BodyPadding="0">
        <Defaults>
            <ext:Parameter Name="margins" Value="0 0 0 0" Mode="Value" />
        </Defaults>
        <Loader runat="server" AutoLoad="false" Mode="Frame">
        </Loader>
    </ext:Window>
    </form>
</body>
</html>
